home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-SPAR.{_6 / OPLIB.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  11KB  |  317 lines

  1. /* $Id: oplib.h,v 1.20 1998/09/17 11:05:25 jj Exp $
  2.  * oplib.h:  Describes the interface and available routines in the
  3.  *           Linux Prom library.
  4.  *
  5.  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6.  */
  7.  
  8. #ifndef __SPARC_OPLIB_H
  9. #define __SPARC_OPLIB_H
  10.  
  11. #include <asm/openprom.h>
  12.  
  13. /* The master romvec pointer... */
  14. extern struct linux_romvec *romvec;
  15.  
  16. /* Enumeration to describe the prom major version we have detected. */
  17. enum prom_major_version {
  18.     PROM_V0,      /* Original sun4c V0 prom */
  19.     PROM_V2,      /* sun4c and early sun4m V2 prom */
  20.     PROM_V3,      /* sun4m and later, up to sun4d/sun4e machines V3 */
  21.     PROM_P1275,   /* IEEE compliant ISA based Sun PROM, only sun4u */
  22.         PROM_AP1000,  /* actually no prom at all */
  23.     PROM_SUN4,    /* Old sun4 proms are totally different, but we'll shoehorn it to make it fit */
  24. };
  25.  
  26. extern enum prom_major_version prom_vers;
  27. /* Revision, and firmware revision. */
  28. extern unsigned int prom_rev, prom_prev;
  29.  
  30. /* Root node of the prom device tree, this stays constant after
  31.  * initialization is complete.
  32.  */
  33. extern int prom_root_node;
  34.  
  35. /* PROM stdin and stdout */
  36. extern int prom_stdin, prom_stdout;
  37.  
  38. /* Pointer to prom structure containing the device tree traversal
  39.  * and usage utility functions.  Only prom-lib should use these,
  40.  * users use the interface defined by the library only!
  41.  */
  42. extern struct linux_nodeops *prom_nodeops;
  43.  
  44. /* The functions... */
  45.  
  46. /* You must call prom_init() before using any of the library services,
  47.  * preferably as early as possible.  Pass it the romvec pointer.
  48.  */
  49. extern void prom_init(struct linux_romvec *rom_ptr);
  50.  
  51. /* Boot argument acquisition, returns the boot command line string. */
  52. extern char *prom_getbootargs(void);
  53.  
  54. /* Device utilities. */
  55.  
  56. /* Map and unmap devices in IO space at virtual addresses. Note that the
  57.  * virtual address you pass is a request and the prom may put your mappings
  58.  * somewhere else, so check your return value as that is where your new
  59.  * mappings really are!
  60.  *
  61.  * Another note, these are only available on V2 or higher proms!
  62.  */
  63. extern char *prom_mapio(char *virt_hint, int io_space, unsigned int phys_addr, unsigned int num_bytes);
  64. extern void prom_unmapio(char *virt_addr, unsigned int num_bytes);
  65.  
  66. /* Device operations. */
  67.  
  68. /* Open the device described by the passed string.  Note, that the format
  69.  * of the string is different on V0 vs. V2->higher proms.  The caller must
  70.  * know what he/she is doing!  Returns the device descriptor, an int.
  71.  */
  72. extern int prom_devopen(char *device_string);
  73.  
  74. /* Close a previously opened device described by the passed integer
  75.  * descriptor.
  76.  */
  77. extern int prom_devclose(int device_handle);
  78.  
  79. /* Do a seek operation on the device described by the passed integer
  80.  * descriptor.
  81.  */
  82. extern void prom_seek(int device_handle, unsigned int seek_hival,
  83.               unsigned int seek_lowval);
  84.  
  85. /* Machine memory configuration routine. */
  86.  
  87. /* This function returns a V0 format memory descriptor table, it has three
  88.  * entries.  One for the total amount of physical ram on the machine, one
  89.  * for the amount of physical ram available, and one describing the virtual
  90.  * areas which are allocated by the prom.  So, in a sense the physical
  91.  * available is a calculation of the total physical minus the physical mapped
  92.  * by the prom with virtual mappings.
  93.  *
  94.  * These lists are returned pre-sorted, this should make your life easier
  95.  * since the prom itself is way too lazy to do such nice things.
  96.  */
  97. extern struct linux_mem_v0 *prom_meminfo(void);
  98.  
  99. /* Miscellaneous routines, don't really fit in any category per se. */
  100.  
  101. /* Reboot the machine with the command line passed. */
  102. extern void prom_reboot(char *boot_command);
  103.  
  104. /* Evaluate the forth string passed. */
  105. extern void prom_feval(char *forth_string);
  106.  
  107. /* Enter the prom, with possibility of continuation with the 'go'
  108.  * command in newer proms.
  109.  */
  110. extern void prom_cmdline(void);
  111.  
  112. /* Enter the prom, with no chance of continuation for the stand-alone
  113.  * which calls this.
  114.  */
  115. extern void prom_halt(void) __attribute__ ((noreturn));
  116.  
  117. /* Set the PROM 'sync' callback function to the passed function pointer.
  118.  * When the user gives the 'sync' command at the prom prompt while the
  119.  * kernel is still active, the prom will call this routine.
  120.  *
  121.  * XXX The arguments are different on V0 vs. V2->higher proms, grrr! XXX
  122.  */
  123. typedef void (*sync_func_t)(void);
  124. extern void prom_setsync(sync_func_t func_ptr);
  125.  
  126. /* Acquire the IDPROM of the root node in the prom device tree.  This
  127.  * gets passed a buffer where you would like it stuffed.  The return value
  128.  * is the format type of this idprom or 0xff on error.
  129.  */
  130. extern unsigned char prom_get_idprom(char *idp_buffer, int idpbuf_size);
  131.  
  132. /* Get the prom major version. */
  133. extern int prom_version(void);
  134.  
  135. /* Get the prom plugin revision. */
  136. extern int prom_getrev(void);
  137.  
  138. /* Get the prom firmware revision. */
  139. extern int prom_getprev(void);
  140.  
  141. /* Character operations to/from the console.... */
  142.  
  143. /* Non-blocking get character from console. */
  144. extern int prom_nbgetchar(void);
  145.  
  146. /* Non-blocking put character to console. */
  147. extern int prom_nbputchar(char character);
  148.  
  149. /* Blocking get character from console. */
  150. extern char prom_getchar(void);
  151.  
  152. /* Blocking put character to console. */
  153. extern void prom_putchar(char character);
  154.  
  155. /* Prom's internal printf routine, don't use in kernel/boot code. */
  156. void prom_printf(char *fmt, ...);
  157.  
  158. /* Query for input device type */
  159.  
  160. enum prom_input_device {
  161.     PROMDEV_IKBD,            /* input from keyboard */
  162.     PROMDEV_ITTYA,            /* input from ttya */
  163.     PROMDEV_ITTYB,            /* input from ttyb */
  164.     PROMDEV_I_UNK,
  165. };
  166.  
  167. extern enum prom_input_device prom_query_input_device(void);
  168.  
  169. /* Query for output device type */
  170.  
  171. enum prom_output_device {
  172.     PROMDEV_OSCREEN,        /* to screen */
  173.     PROMDEV_OTTYA,            /* to ttya */
  174.     PROMDEV_OTTYB,            /* to ttyb */
  175.     PROMDEV_O_UNK,
  176. };
  177.  
  178. extern enum prom_output_device prom_query_output_device(void);
  179.  
  180. /* Multiprocessor operations... */
  181.  
  182. /* Start the CPU with the given device tree node, context table, and context
  183.  * at the passed program counter.
  184.  */
  185. extern int prom_startcpu(int cpunode, struct linux_prom_registers *context_table,
  186.              int context, char *program_counter);
  187.  
  188. /* Stop the CPU with the passed device tree node. */
  189. extern int prom_stopcpu(int cpunode);
  190.  
  191. /* Idle the CPU with the passed device tree node. */
  192. extern int prom_idlecpu(int cpunode);
  193.  
  194. /* Re-Start the CPU with the passed device tree node. */
  195. extern int prom_restartcpu(int cpunode);
  196.  
  197. /* PROM memory allocation facilities... */
  198.  
  199. /* Allocated at possibly the given virtual address a chunk of the
  200.  * indicated size.
  201.  */
  202. extern char *prom_alloc(char *virt_hint, unsigned int size);
  203.  
  204. /* Free a previously allocated chunk. */
  205. extern void prom_free(char *virt_addr, unsigned int size);
  206.  
  207. /* Sun4/sun4c specific memory-management startup hook. */
  208.  
  209. /* Map the passed segment in the given context at the passed
  210.  * virtual address.
  211.  */
  212. extern void prom_putsegment(int context, unsigned long virt_addr,
  213.                 int physical_segment);
  214.  
  215.  
  216. /* PROM device tree traversal functions... */
  217.  
  218. #ifdef PROMLIB_INTERNAL
  219.  
  220. /* Internal version of prom_getchild. */
  221. extern int __prom_getchild(int parent_node);
  222.  
  223. /* Internal version of prom_getsibling. */
  224. extern int __prom_getsibling(int node);
  225.  
  226. #endif
  227.  
  228.  
  229. /* Get the child node of the given node, or zero if no child exists. */
  230. extern int prom_getchild(int parent_node);
  231.  
  232. /* Get the next sibling node of the given node, or zero if no further
  233.  * siblings exist.
  234.  */
  235. extern int prom_getsibling(int node);
  236.  
  237. /* Get the length, at the passed node, of the given property type.
  238.  * Returns -1 on error (ie. no such property at this node).
  239.  */
  240. extern int prom_getproplen(int thisnode, char *property);
  241.  
  242. /* Fetch the requested property using the given buffer.  Returns
  243.  * the number of bytes the prom put into your buffer or -1 on error.
  244.  */
  245. extern int prom_getproperty(int thisnode, char *property,
  246.                 char *prop_buffer, int propbuf_size);
  247.  
  248. /* Acquire an integer property. */
  249. extern int prom_getint(int node, char *property);
  250.  
  251. /* Acquire an integer property, with a default value. */
  252. extern int prom_getintdefault(int node, char *property, int defval);
  253.  
  254. /* Acquire a boolean property, 0=FALSE 1=TRUE. */
  255. extern int prom_getbool(int node, char *prop);
  256.  
  257. /* Acquire a string property, null string on error. */
  258. extern void prom_getstring(int node, char *prop, char *buf, int bufsize);
  259.  
  260. /* Does the passed node have the given "name"? YES=1 NO=0 */
  261. extern int prom_nodematch(int thisnode, char *name);
  262.  
  263. /* Puts in buffer a prom name in the form name@x,y or name (x for which_io 
  264.  * and y for first regs phys address
  265.  */
  266. extern int prom_getname(int node, char *buf, int buflen);
  267.  
  268. /* Search all siblings starting at the passed node for "name" matching
  269.  * the given string.  Returns the node on success, zero on failure.
  270.  */
  271. extern int prom_searchsiblings(int node_start, char *name);
  272.  
  273. /* Return the first property type, as a string, for the given node.
  274.  * Returns a null string on error.
  275.  */
  276. extern char *prom_firstprop(int node, char *buffer);
  277.  
  278. /* Returns the next property after the passed property for the given
  279.  * node.  Returns null string on failure.
  280.  */
  281. extern char *prom_nextprop(int node, char *prev_property, char *buffer);
  282.  
  283. /* Returns phandle of the path specified */
  284. extern int prom_finddevice(char *name);
  285.  
  286. /* Returns 1 if the specified node has given property. */
  287. extern int prom_node_has_property(int node, char *property);
  288.  
  289. /* Set the indicated property at the given node with the passed value.
  290.  * Returns the number of bytes of your value that the prom took.
  291.  */
  292. extern int prom_setprop(int node, char *prop_name, char *prop_value,
  293.             int value_size);
  294.             
  295. extern int prom_pathtoinode(char *path);
  296. extern int prom_inst2pkg(int);
  297.  
  298. /* Dorking with Bus ranges... */
  299.  
  300. /* Adjust reg values with the passed ranges. */
  301. extern void prom_adjust_regs(struct linux_prom_registers *regp, int nregs,
  302.                  struct linux_prom_ranges *rangep, int nranges);
  303.  
  304. /* Adjust child ranges with the passed parent ranges. */
  305. extern void prom_adjust_ranges(struct linux_prom_ranges *cranges, int ncranges,
  306.                    struct linux_prom_ranges *pranges, int npranges);
  307.  
  308. /* Apply promlib probed OBIO ranges to registers. */
  309. extern void prom_apply_obio_ranges(struct linux_prom_registers *obioregs, int nregs);
  310.  
  311. /* Apply ranges of any prom node (and optionally parent node as well) to registers. */
  312. extern void prom_apply_generic_ranges(int node, int parent, 
  313.                       struct linux_prom_registers *sbusregs, int nregs);
  314.                    
  315.  
  316. #endif /* !(__SPARC_OPLIB_H) */
  317.